package practice1_100;

public class Practice525 {
    public int findMaxLength(int[] nums) {
        int[][][] count=new int[nums.length][nums.length][2];
        for(int i=0;i<nums.length;i++){
            if(nums[i]==0)count[i][i][0]=1;
            else count[i][i][1]=1;
        }
        int maxlen=1;
        for(int i=1;i<nums.length;i++){
            for(int j=0;j<i;j++){
                if(nums[i]==1){
                    count[j][i][1]=count[j][i-1][1]+1;
                    count[j][i][0]=count[j][i-1][0];
                }else{
                    count[j][i][0]=count[j][i-1][0]+1;
                    count[j][i][1]=count[j][i-1][1];
                }
            }
        }
        for(int i=0;i<nums.length;i++){
            for(int j=0;j<nums.length;j++){
                if (count[i][j][1]==count[i][j][0])maxlen=maxlen>count[i][j][1]?maxlen:count[i][j][1];
            }
        }
        return maxlen*2;
    }

    public static void main(String[] args) {
        int a=new Practice525().findMaxLength(new int[]{0,1,1,0,1,0,1,1,0,1,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0,1,1,0,0,1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,1,1,0,0,1,1,1,1,1,0,1,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,1,1,0,1,1,1,1,0,1,0,0,1,0,1,1,0,0,1,1,1,1,0,0,0,0,1,1,0,0,0,1,1,0,1,0,1,1,0,0,0,0,1,0,1,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,0,1,1,1,0,1,0,0,1,1,0,0,1,1,0,1,1,1,1,1,0,1,0,0,1,0,1,1,0,1,1,0,0,0,0,1,0,1,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0,0,1,1,1,0,0,1,0,1,1,0,1,1,1,1,0,1,1,0,1,0,0,1,0,0,0,1,1,0,0,1,0,0,1,0,0,0,1,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,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